//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public class CategoryAxis : Axis
    {
        private const int defaultSkip = 0;
        private const string name = "catAx";

        private bool _auto;
        private LabelAlignment _labelAlignment;

        private int _labelOffset;
        private bool _noMultiLvlLbl;
        private int _tickLblSkip = defaultSkip;
        private int _tickMarkSkip = defaultSkip;

        public bool Auto
        {
            get { return _auto; }
            set { _auto = value; notifyPropertyChanged("Auto");}
        }

        public int LabelOffset
        {
            get { return _labelOffset; }
            set { _labelOffset = value; notifyPropertyChanged("LabelOffset");}
        }

        public LabelAlignment LabelAlignment
        {
            get { return _labelAlignment; }
            set { _labelAlignment = value; notifyPropertyChanged("LabelAlignment");}
        }


        public int TickLabelSkip
        {
            get { return _tickLblSkip; }
            set { _tickLblSkip = value; notifyPropertyChanged("TickLabelSkip");}
        }

        public int TickMarkSkip
        {
            get { return _tickMarkSkip; }
            set { _tickMarkSkip = value; notifyPropertyChanged("TickMarkSkip");}
        }

        public bool NoMultiLevelLabel
        {
            get { return _noMultiLvlLbl; }
            set { _noMultiLvlLbl = value; notifyPropertyChanged("NoMultiLevelLabel");}
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read(name))
            {
                c.PassAttributes();
                ReadXmlBase(context);
                Auto = c.ReadOptionalElementBooleanAttribute("auto", false); //\\default?
                _labelAlignment =
                    c.ReadOptionalElementEnumAttribute("lblAlgn", "val", LabelAlignment.Left,
                                                                       LabelAlignment.Left); //\\default?
                LabelOffset = c.ReadOptionalElementIntegerAttribute("lblOffset", "val", 100); //\\int?
                _tickLblSkip = c.ReadOptionalElementIntegerAttribute("tickLblSkip", "val", defaultSkip); //\\default?
                _tickMarkSkip = c.ReadOptionalElementIntegerAttribute("tickMarkSkip", "val", defaultSkip); //\\default?
                _noMultiLvlLbl = c.ReadOptionalElementBooleanAttribute("noMultiLvlLbl", false); //\\default?
                Extension = c.ReadOptionalElement<ExtensionElement>("extLst");
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write(name))
            {
                {
                    WriteXmlBase(context);
                    c.WriteOptionalElementBooleanAttribute("auto", Auto, false);
                    c.WriteOptionalElementEnumAttribute("lblAlgn", "val", _labelAlignment,
                                                                        LabelAlignment.Left, LabelAlignment.Left);
                        //\\default?
                    c.WriteOptionalElementIntegerAttribute("lblOffset", "val", LabelOffset, 100); //\\int?
                    c.WriteOptionalElementIntegerAttribute("tickLblSkip", "val", _tickLblSkip, defaultSkip); //\\default?
                    c.WriteOptionalElementIntegerAttribute("tickMarkSkip", "val", _tickMarkSkip, defaultSkip);
                        //\\default?
                    c.WriteOptionalElementBooleanAttribute("noMultiLvlLbl", _noMultiLvlLbl, false); //\\default?
                    c.WriteOptionalElement(Extension);
                }
            }
        }
    }
}